SPB Git

Repository Public

route.ts 1.0 KB 18 lines typescript

1import { getCourse, mediaStorage } from "@/lib/content";2import { env } from "@/lib/env";3import { notFoundResponse, serveObject } from "@/lib/serve";4import { mediaAllowed } from "@/modules/content-schema";56export const dynamic = "force-dynamic";78/** Capsule media (HLS playlists and segments, MP4, poster, captions, transcript, chapters). */9async function handle(request: Request, { params }: { params: Promise<{ path: string[] }> }) {10  const key = (await params).path.join("/");11  // Permission first: media of a capsule that is not published does not exist for the visitor.12  if (!mediaAllowed(await getCourse(), key)) return notFoundResponse();13  // Files are never rewritten in place (each encode and each caption file has its own name), so they could be14  // cached for long; an hour keeps a withdrawn capsule from lingering in shared caches.15  return serveObject(mediaStorage(), key, request, { cache: env.mode === "preview" ? "private, no-store" : "public, max-age=3600" });16}17export { handle as GET, handle as HEAD };18
Files main
Menu

Theme